package com.itheima.health.service.impl;

import com.itheima.health.dao.OrderSettingDao;
import com.itheima.health.pojo.OrderSetting;
import com.itheima.health.service.OrderSettingService;
import com.itheima.health.utils.DateUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author hm
 * @version 1.0
 * @date Created in 2024/7/15 17:44
 */
@Service
public class OrderSettingServiceImpl implements OrderSettingService {
    @Resource
    private OrderSettingDao orderSettingDao;

    @Override
    public void add(OrderSetting orderSetting) {
        OrderSetting byOrderDate = orderSettingDao.findByOrderDate(orderSetting.getOrderDate());
        if (byOrderDate != null) {
            orderSettingDao.update(orderSetting);
        } else {
            orderSettingDao.add(orderSetting);
        }
    }

    @Override
    public List<OrderSetting> getByDate(Date month) {
        Date begin = DateUtils.getFirstDay4Date(month);
        Date end = DateUtils.getLastDay4Date(month);
        System.out.println("begin = " + begin);
        System.out.println("end = " + end);
        List<OrderSetting> list = orderSettingDao.getByDate(begin, end);
        return list;
    }

    @Override
    public void update(OrderSetting orderSetting) {
        orderSettingDao.update(orderSetting);
    }

    @Override
    public OrderSetting findByOrderDate(Date orderDate) {
       return orderSettingDao.findByOrderDate(orderDate);
    }
}
